package com.jt.auth.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
/*
创建JWT令牌配置类,基于这个类实现令牌对象的创建和解析
JWT令牌有三部分构成:
1.Header(头部信息)
2.Payload(数据信息-用户信息,权限信息)
3.Signature(签名信息)
 */
@Configuration
public class TokenConfig {
    //定义令牌签发口令
    private String SIGNING_KEY = "auth";
    //初始化令牌构建和存储对象
    //采用JWT方式生成令牌
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(jwtAccessTokenConverter());
    }
    //构建令牌转换器对象,基于此对象创建令牌,解析令牌
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
    JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
    converter.setSigningKey(SIGNING_KEY);
    return converter;
    }
}
